﻿using DAL;
using System;
using System.Data;
using System.Windows.Forms;
using word;

namespace work
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
            checkService();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (TB_Val.Text.ToString()==GetVCode.RandomCode)
            {
                String userName = TB_Name.Text.ToString();
                String pwd = TB_pwd.Text.ToString();
                String sql = $"select * from Users where u_Name ='{TB_Name.Text.ToString()}' and u_Password = '{GetMD5.getStr(TB_pwd.Text.ToString())}'";
                DataTable dataTable = DBHelper.Select(sql);
                if (dataTable.Rows.Count > 0)
                {
                    Main main = new Main();
                    this.Hide();
                    main.Show();

                }
                else
                {
                    MessageBox.Show("账号密码错误", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("验证码不正确", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }

        private void TB_Picture_Click(object sender, EventArgs e)
        {

        }

        private void login_Load(object sender, EventArgs e)
        {
       
            GetVCode.GetRandomCode();
            TB_Picture.Image = GetVCode.CreateImage(TB_Picture, 16);
        }

        private void label5_Click(object sender, EventArgs e)
        {
            GetVCode.GetRandomCode();
            TB_Picture.Image = GetVCode.CreateImage(TB_Picture, 16);
        }

        public void checkService()
        {
            try
            {
                if (DBHelper.Connection.State != ConnectionState.Open)
                {
                   
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("服务器无相应" + ex.Message, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
            
        }
    }
}
